#coding:utf-8
"""
Django settings for learn_django project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9dxo4(%#o+u*qca+)$+07dd-)k2)&^2pc3f&_i448-+ua!fy+#'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'day20',
    #'masonAuth',
    'appMonitor',
    'grafanaCallBack',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'learn_django.urls'

WSGI_APPLICATION = 'learn_django.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
# '''
# CREATE DATABASE `yunweisys` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin */;
# select user,host from mysql.user;
# grant all on yunweisys.* to yunweisys@'192.168.1.0/24' identified by 'yunweisys';
# grant all on yunweisys.* to yunweisys@'127.0.0.1' identified by 'yunweisys';
# grant all on yunweisys.* to yunweisys@'localhost' identified by 'yunweisys';
# flush privileges;
# '''
# if os.name == 'posix':
#     DATABASES = {
#         'default': {
#             'ENGINE': 'django.db.backends.mysql',
#             'HOST':'192.168.1.48',
#             'NAME':'yunweisys',
#             'USER':'yunweisys',
#             'PASSWORD':'yunweisys',
#             'PORT':'3306',
#         }
#     }
# else:
#     DATABASES = {
#         'default': {
#             'ENGINE': 'django.db.backends.mysql',
#             'HOST': '127.0.0.1',
#             'NAME': 'yunweisys',
#             'USER': 'yunweisys',
#             'PASSWORD': 'yunweisys',
#             'PORT': '3306',
#         }
#     }

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

#LANGUAGE_CODE = 'en-us'
#LANGUAGE_CODE = 'zh-cn'
LANGUAGE_CODE = 'zh-hans'

#TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

#USE_TZ = True
USE_TZ = False

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'

TEMPLATE_DIRS = (os.path.join(BASE_DIR,  'templates'),)


#我自己添加部分
STATICFILES_DIRS = (
    os.path.join(BASE_DIR,'static/'),
)
#AUTH_USER_MODEL = 'masonAuth.UserProfile'
#AUTH_USER_MODEL = 'masonAuth.MasonUser'
#AUTH_USER_MODEL = 'masonAuth.MyUser'




# 定义日志格式
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_LOG_DIR = os.path.join(BASE_DIR, "log")
if not os.path.exists(BASE_LOG_DIR):
    os.makedirs(BASE_LOG_DIR)
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
       'default': {
            #'format': '[%(levelname)s] [%(name)s] %(asctime)s %(module)s %(process)d %(thread)d %(message)s'}
            'format': '%(asctime)s %(levelname)s %(name)s %(threadName)s:%(thread)d task_id:%(name)s %(filename)s:%(lineno)d %(message)s'}
    },

    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
    },

    'handlers': {
        'console' :{
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter':'default',
        },
        'mail_admin': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': False,
        },
        'error': {
            'level':'ERROR',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(BASE_LOG_DIR, 'error.log'),
            'maxBytes':1024 * 1024 * 1,
            'backupCount': 5,
            'formatter':'default',
        },
        'warn': {
            'level': 'WARNING',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(BASE_LOG_DIR, 'warn.log'),
            'maxBytes': 1024 * 1024 * 1,
            'backupCount': 5,
            'formatter': 'default',
        },
    },

    'loggers': {
        'django': {
            'handlers': ['warn', 'error', 'console'],
            'level': 'INFO',
            'propagate': False
        },
        'django.request': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False
        }
    }
}